delete(instrfindall);
g=serial('com10');                                     
set(g,'BaudRate',115200,'StopBits',1,'Parity','none','DataBits',8,'InputBufferSize',8000);
fopen(g);

fileprefix = 'anchor1_10cm';
measurementLength =1000;
distances =zeros(1,measurementLength);
measurementIndex = 0;
while(true)
  str  = fscanf(g,'%s');
  a    = sscanf(str,'distance%d:%dmm,');
  if length(a)==2
    % disp(a);
    measurementIndex = measurementIndex+1;
    if(measurementIndex>measurementLength)
      save(strcat(fileprefix,'_',num2str(round(now*1e6)),'.mat'));
      break;
    else
      distances(1,measurementIndex)= a(2);
    end
  elseif length(a)~=0
    warning('there are some mistakes');
  end
end
